#include	"stdafx.h"
#include	"Patcher.h"

//////////////////////////////////////////////////////////////////////////
struct Function 
{
	DWORD	m_Address;
	LPVOID	m_Handler;
};

Function	Hooks[] =
{
	// Joes
	0x00527960, &CreateDirectDraw,
	0x00527E60, &FlipSurface,
	0x005277B0, &WinMain,
	0x005281A0, &UnlockAppropriateRenderBuffer,
	0x00528500, &UnlockPrimarySurface,
	0x00527E10, &BlitToBackbuffer,
	0x005272F0, &DrawCursorXY,
	0x00526EF0,	&ForceCursorPos,
	0x005273C0, &CreateCursorSurfaces,
	0x00527090, &DrawAutoCursor,
	0x00528B30, &RestoreSurfaces,
	0x00527D30,	&CleanupSurfaces,
	// struct
	0x0052CFB5, &struct_Test_Bit_Field_,
	0x0052CFED, &struct_Set_Bit_Field_,
	0x0052D027, &struct_Clear_Bit_Field_,
	0x0052D0B7,	&struct_Clear_Structure_,
	0x0052D0FA, &struct_Copy_Structure_,
	// HACCESS
	0x0049B270, &HACCESS_Ship_Owner_,
	NULL,		NULL
};
//////////////////////////////////////////////////////////////////////////
void	InstallHooks()
{
	Function * func = &Hooks[0];
	while (func->m_Address != NULL)
	{
		nPatcher::CreateJmp((LPVOID)func->m_Address, func->m_Handler);
		++func;
	}
}

int WINAPI DllMain(HINSTANCE hInstance, DWORD dwReason, LPVOID lpvReserved)
{	
	if (dwReason == DLL_PROCESS_ATTACH)
	{	
		// Intialize logs
		pLog.SetEnable(TRUE);
		nConfig::Initialize();

		InitializeFunctionDef();

		InstallHooks();		

		pLog.Write("Initialized.\n");

		if (nConfig::Debug_Breakpoint)
		{
			MessageBox(0, "I am MessageBox from MOO2. You can now switch to debugger.", "MOO2", MB_OK);
		}
	} else
	if (dwReason == DLL_PROCESS_DETACH)
	{
	}

	return TRUE;
}
